package com.burgeon.backend.SHOP.controller;
/**
 * 韩起航
 * 2020/3/24
 */

import com.burgeon.backend.SHOP.entity.Favoritesgoods;
import com.burgeon.backend.SHOP.service.FavoritesService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;

@RestController
@RequestMapping("shop/favorites")
public class FavoritesController extends BaseController {
    @Autowired
    FavoritesService favoritesService;


    @RequestMapping("add")
    public ResponseResult addgoodfavorites(String gid, HttpSession session) {
        if (null == session.getAttribute("uid")){
            return new ResponseResult(NOTLOG);
        }
        String uid = session.getAttribute("uid").toString();
        String token = session.getAttribute("token").toString();
        favoritesService.addfavoritesservice(gid, uid, token);
        return new ResponseResult(SUCCESS);
    }

    @RequestMapping("delect")
    public ResponseResult del(String id) {

        favoritesService.delect(id);

        return new ResponseResult(SUCCESS);
    }

    @RequestMapping("select")
    public ResponseResult<ArrayList<Favoritesgoods>> sel(HttpSession session) {
        String token = session.getAttribute("token").toString();
        String uid = session.getAttribute("uid").toString();
        ArrayList<Favoritesgoods> data = favoritesService.select(token, uid);
        return new ResponseResult<ArrayList<Favoritesgoods>>(SUCCESS, data);
    }
}